package your.rfgui.application.data;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import your.rfgui.extgui.data.intf.GuiParentChildEntity;

public class MyParentChildEntity extends CommonBaseEntity implements GuiParentChildEntity<MyParentChildEntity> {

   private static final Logger log = Logger.getLogger(MyParentChildEntity.class);
   // data attribtues
   private String name;
   private long number;
   private MyParentChildEntity parent;
   private List<MyParentChildEntity> children = new ArrayList<MyParentChildEntity>();
   private static int next_number;

   public MyParentChildEntity() {
      this.number = next_number++;
      this.id = number;
   }

   public MyParentChildEntity(String name) {
      this();
      this.name = name;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public long getNumber() {
      return number;
   }

   public void setNumber(long number) {
      this.number = number;
   }

   public String getLabel() {
      return name;
   }

   public MyParentChildEntity getParent() {
      return parent;
   }

   public void setParent(MyParentChildEntity parent) {
      if (this.parent != null) {
         this.parent.getChildren().remove(this);
      }
      if (parent != null) {
         parent.getChildren().add(this);
      }
      this.parent = parent;
   }

   public List<MyParentChildEntity> getChildren() {
      return children;
   }

   public void clearChildren() {
      children.clear();
   }

}
